﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cash.Model;
using CashCommon;
using System.Data;
using System.Globalization;

namespace Cash
{
    public class Reports
    {
        public List<Fill> Gets()
        {
            return _fill;
        }
        public List<FillResult> GetsResult()
        {
            return _fillResult;
        }
        public void Init(DateTime dateTime)
        {

            SqlSwitch sqlSwitch = new SqlSwitch();

            sqlSwitch.Add("D_Date_Search", dateTime.ToString("yyyyMMdd"), SqlCondition.equal, SqlType.sqlDate, Direction.input);
            sqlSwitch.Add("F_Division", CashEmployer.Inst.F_Division, SqlCondition.in_enum, SqlType.sqlInt, Direction.input);

            Sequence sqc = Builder.CashRegisterGate.GetSequence(null);
            if (sqlSwitch != null)
                sqc.SqlSwitch = sqlSwitch;
            sqc.PrimaryKey.Add("LINK");
            sqc.Open();

            StringBuilder sb = new StringBuilder();

            foreach (DataRow item in sqc.DT.Rows)
            {
                _fill.Add(new Fill(
                    item["N_CODE"].ToString(),
                    item["ABONENTNAME"].ToString(),
                    Properties.Settings.Default.CorrAccount,
                    Convert.ToDouble(item["N_AMOUNT"], CultureInfo.InvariantCulture)
                    ));
            }
            _fillResult.Add(new FillResult(_fill.Sum(w => w.Amount), dateTime.ToShortDateString()));

        }

        #region Fields

        private List<Fill> _fill = new List<Fill>();
        private List<FillResult> _fillResult = new List<FillResult>();

        #endregion
    }

    public class Fill
    {
        public Fill(string checkNumber, string abonent, string account, double amount)
        {
            _checkNumber = checkNumber;
            _abonent = abonent;
            _account = account;
            _amount = amount;
        }

        /// <summary>
        /// Номер чека
        /// </summary>
        public string CheckNumber
        {
            get { return _checkNumber; }
            set { _checkNumber = value; }
        }
        /// <summary>
        /// От кого получено
        /// </summary>
        public string Abonent
        {
            get { return _abonent; }
            set { _abonent = value; }
        }
        /// <summary>
        /// Кор. счет
        /// </summary>
        public string Account
        {
            get { return _account; }
            set { _account = value; }
        }
        /// <summary>
        /// Приход, руб.
        /// </summary>
        public double Amount
        {
            get { return _amount; }
            set { _amount = value; }
        }

        #region Fields
        
        private string _checkNumber, _abonent, _account;
        private double _amount;
        
        #endregion

    }
    public class FillResult
    {
        public FillResult(double amount, string dateReport)
        {
            this._amount = amount;
            this._dateReport = dateReport;
        }
        
        public double Amount
        {
            get { return _amount; }
            set { _amount = value; }
        }
        public string DateReport
        {
            get { return _dateReport; }
            set { _dateReport = value; }
        }

        #region Fields
        
        private double _amount;
        private string _dateReport;

        #endregion

    }
}
